package com.jwj.testback.recordsheet.controller;


import com.jwj.testback.recordsheet.pojo.Datasource;
import com.jwj.testback.recordsheet.pojo.TableField;
import com.jwj.testback.recordsheet.pojo.Tableware;
import com.jwj.testback.recordsheet.service.DatasourceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JWJ
 * @since 2021-12-21
 */
@Controller
@RequestMapping("/datasource")
public class DatasourceController {
    @Resource
    private DatasourceService datasourceService;

    //显示所有数据源
    @ApiOperation(value = "显示数据源")
    @ResponseBody
    @CrossOrigin
    @RequestMapping(value = "/showDateBase",method = RequestMethod.GET)
    public List<Datasource> showDataBases() {
        List<Datasource> datasources = datasourceService.showDataBases();
        return datasources;
    }

    //切换数据源并显示该数据源所有表
    @ApiOperation(value = "显示所有表")
    @ResponseBody
    @CrossOrigin
    @RequestMapping(value = "/showTables",method = RequestMethod.GET)
    public List<Tableware> showTables(String databaseName){
        List<Tableware> list = datasourceService.showTables(databaseName);
        return list;
    }

    @ApiOperation(value = "显示所有表大小")
    @ResponseBody
    @CrossOrigin
    @RequestMapping(value = "/tableSize",method = RequestMethod.GET)
    public List<Tableware> TableSize(String databaseName){
        List<Tableware> tableSize = datasourceService.TableSize(databaseName);
        return tableSize;
    }

    @ApiOperation(value = "显示表字段")
    @ResponseBody
    @CrossOrigin
    @RequestMapping(value = "/showField",method = RequestMethod.GET)
    public List<TableField> showField(String tableName,String databaseName){
        List<TableField> tableFields = datasourceService.showField(tableName,databaseName);
        return tableFields;
    }

    @ApiOperation(value = "查找用户名密码")
    @ResponseBody
    @CrossOrigin
    @RequestMapping(value = "/showNamePas",method = RequestMethod.GET)
    public Datasource showNamePas(String databaseName){
        Datasource datasource = datasourceService.showNamePas(databaseName);
        return datasource;
    }

}

